package com.stockz.indicator.vsa.property;

import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.core.util.BarUtil;
import com.stockz.core.util.BarUtil.BarValueType;
import com.stockz.indicator.vsa.VsaBar;

public class Spread extends RangeEnum {

	public static final Spread Wide = new Spread("Wide",1,Double.MAX_VALUE,131);
	public static final Spread Average = new Spread("Average",2,130,71);
	public static final Spread Narrow = new Spread("Narrow",3,70,61);
	public static final Spread UltraNarrow = new Spread("UltraNarrow",4,60,0);
	
	private static final Spread[] spreads = new Spread[]{Wide,Average,Narrow,UltraNarrow};
	
	public static Spread[] values(){
		return spreads;
	}
	
	public static void analyze(List<Bar> barList,double[] ssma, int index, VsaBar vsaBar){
		if(barList == null || barList.isEmpty() || ssma == null || 0 == ssma.length || 
				index < 0 || index >= barList.size() || index >= ssma.length || vsaBar == null || ssma[index] == 0){
			return;
		}
		double percentage = BarUtil.getValue(barList.get(index),BarValueType.SPREAD)*100/ssma[index];
		for(Spread spread : Spread.values()){
			if(percentage <= spread.getUpperLimit() && percentage >= spread.getLowerLimit()){
				vsaBar.setSpread(spread);
				break;
			}
		}
	}
	
	private Spread(String name, int ordinal, double upperLimit, double lowerLimit) {
		super(name, ordinal, upperLimit, lowerLimit);
	}

}
